package configuration;

import java.io.File;
import java.util.ResourceBundle;

/**
 * @author Karl
 * @Date 2023/1/2 - 14:37
 */
public class MyConfiguration {

    private MyConfiguration(){}


    public static String fileRoot = "D:/myStatic/";

    public static int CacheTime = 60000;

    public static Integer port = null;

    public static String cacheExpireHeader = "Proxy-Cache-Time";

    static {
        try {
            ResourceBundle bundle = ResourceBundle.getBundle("configuration");
            if (bundle.containsKey("port")) {
                port = Integer.parseInt(bundle.getString("port"));
            }
            if (bundle.containsKey("fileRoot")) {
                fileRoot = bundle.getString("fileRoot");;
                File file = new File(fileRoot);
                if(!file.exists()&&!file.mkdirs()){
                    System.out.println("缓存路径配置错误或者没有配置!");
                }
            }

        }catch (Exception e){
            System.out.println("找不到配置文件configuration.properties!");
        }
    }

    public static Integer getPort() {
        return port;
    }

    public static String getFileRoot() {
        return fileRoot;
    }

    public static int getCacheTime() {
        return CacheTime;
    }


    public static String getCacheExpireHeader() {
        return cacheExpireHeader;
    }
}
